package controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.Enumeration;

@WebServlet("/empmain")
public class MainContraller extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //响应头
        response.setStatus(500,"错!");
        //响应行
        response.setContentType("text/html;charset=utf-8");

        response.setHeader("ContentType","text/html;charset=utf-8");
        response.setHeader("className","dz18");
        //响应主体
        response.getWriter().println("<a>我是响应主体</a>");

    }
    public void showrequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        //获得请求方式
        String method = request.getMethod();
        System.out.println("请求方式:" + method);
        //获得请求地址:
        System.out.println("uri:"+request.getRequestURI());
        System.out.println("url:"+request.getRequestURL());
        //获得协议:
        System.out.println("协议名称:"+request.getScheme());
        //获得版本:
        System.out.println("版本:"+request.getProtocol());
        //获得项目名
        System.out.println("项目名:"+request.getContextPath());
        //获得请求行信息
        System.out.println("请求行"+request.getHeader("Accept"));
        Enumeration<String> headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()){
            String s=headerNames.nextElement();
            System.out.println("请求行"+s+":"+request.getHeader(s));
        }
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //获得[请求主体]的信息
        String empno=request.getParameter("empno");
        String ename=request.getParameter("ename");
        String sex=request.getParameter("sex");
        String[] citys=request.getParameterValues("citys");
        String birthYear=request.getParameter("birthYear");
        System.out.println("员工编号:"+empno);
        System.out.println("员工姓名:"+ename);
        System.out.println("性别:"+sex);
        System.out.println("城市:"+ Arrays.toString(citys));
        System.out.println("出生年份:"+birthYear);
    }
}
